﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace XHCTMS.View
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GetTreeView();
        }
        private void GetTreeView()//程序开始
        {
            try
            {
                SqlConnection getConn = new SqlConnection("server=.; database=xhctmsace; integrated security=SSPI");
                string strSql = @"select  sub_id,sub_name from sub";
                SqlDataAdapter objAdapter = new SqlDataAdapter(strSql, getConn);
                DataSet ds = new DataSet();
                ds.Clear();
                objAdapter.Fill(ds, "temp");
                DataTable dt = ds.Tables["temp"];
                TreeView1.Nodes.Clear();
                TreeView1.ExpandDepth = 0;
                //建立根节点，遍历。

                foreach (DataRow dr in dt.Rows)
                {
                    TreeNode Root = new TreeNode();
                    Root.SelectAction = TreeNodeSelectAction.Expand;
                    Root.Text = dr["sub_name"].ToString();
                    TreeView1.Nodes.Add(Root);//建立根节点
                    string str = @"select  class_name+'--'+teaching_lesson as t, class_id,teaching_id from teaching, class,sub
                                where class_sub_id=sub_id and teaching_class_Id = class_id and sub_id=" + dr["sub_id"].ToString();
                    SqlDataAdapter objAdapterNode = new SqlDataAdapter(str, getConn);

                    DataSet dsNode = new DataSet();
                    dsNode.Clear();
                    objAdapterNode.Fill(dsNode, "tempNode");
                    DataTable dtNode = dsNode.Tables["tempNode"];

                    //建立子节点，遍历。
                    foreach (DataRow drNode in dtNode.Rows)
                    {
                        TreeNode Node = new TreeNode();
                        Node.Text = drNode["t"].ToString();
                        Node.Target = "show";
                        string Path = drNode["class_id"].ToString();
                        string teachingPath = drNode["teaching_id"].ToString();
                        //int menusn = Convert.ToInt32(drNode["sn"].ToString());
                        Node.NavigateUrl = "Checking.aspx" + "?class_id=" + Path + "&teaching_id=" + teachingPath;
                        Root.ChildNodes.Add(Node);//建立子节点                        
                    }
                }
            }
            catch
            {
                Response.Write(" alert('您没有可操作的菜单项，请与管理员联系!'); ");
            }
            finally
            {
                
            }
        }       
    }
}